package com.micro.controller;

import com.micro.model.KnowLib;
import com.micro.service.KnowLibService;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/knowLib")
public class KnowLibController {
	private ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"classpath:conf/spring.xml"
			,"classpath:conf/spring-mybatis.xml"});

	/**
	 * 查询知识库
	 * @params response
	 * @throws IOException
	 */
	@RequestMapping("queryKnowLibList.do") //"value="qryInitData.do",method=RequestMethod.POST
	public void queryKnowLibList(HttpServletResponse response) throws IOException {
		KnowLibService knowLibService = (KnowLibService) context.getBean("knowLibServiceImpl");
		List<KnowLib> knowLibList = knowLibService.queryKnowLibList();


		ObjectMapper objectMapper = new ObjectMapper();
		String jsonString = objectMapper.writeValueAsString(knowLibList);
		response.getWriter().write(jsonString);
	}
}
